[bash] Escape a string for sed search pattern
Posted
by Alexander Gladysh
on Stack Overflow
See other posts from Stack Overflow
or by Alexander Gladysh
Published on 2009-01-02T17:44:15Z
Indexed on
2010/04/24
18:43 UTC
Read the original article
Hit count: 299
In my bash
script I have an external (received from user) string, which I should use in sed
pattern.
REPLACE="<funny characters here>"
sed "s/KEYWORD/$REPLACE/g"
How can I escape the $REPLACE
string so it would be safely accepted by sed
as a literal replacement?
NOTE: The KEYWORD
is a dumb substring with no matches etc. It is not supplied by user.
© Stack Overflow or respective owner